// 解析url
function parsUrl(urlStr) {
  let decStr = decodeURI(urlStr);
  let arr = decStr.split('&');
  let obj = {};
  for (let i = 0; i < arr.length; i++) {
      let l = arr[i].indexOf('=');
      obj[arr[i].substr(0, l)] = arr[i].substring(l + 1)
  }
  if (obj.result) {
      obj.result = JSON.parse(obj.result);
  }
  return obj
}

function getUrlInfo(str) {
  return new Promise((resolve, reject) => {
      if (!str || str === '') {
          str = window.location.search.substr(1);
      }
      if (str.length === 0) {
          reject(new Error('未获取到数据'))
      } else {
          let data = parsUrl(str);
          resolve(data);
      }
  })
}

export {getUrlInfo}